<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>名片转化的会员</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<style type="text/css">
body{font-size: 14px;}
.dataTables_info {font-size: 12px}
.dataTables_paginate {font-size: 12px;}
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
	<div class="row" style="height: 40px;">
		<div class="col-sm-12">
			<a href="javascript:window.history.back();" style="color: #1ab394;">返回</a>
		</div>
	</div>
	<div class="row">
		<div class="col-sm-1" style="line-height: 34px;">
			筛选状态
		</div>
		<div class="col-sm-2">
			<select id="contacted" class="form-control">
				<option value="0">未联系</option>
				<option value="1">已联系</option>
			</select>
		</div>
		<div class="col-sm-3">
			<div class="input-group">
	            <input id="keyword" placeholder="输入名称搜索" type="text" class="form-control"> <span class="input-group-btn"> 
	            <button id="search" type="button" class="btn btn-primary">搜索</button> </span>
	        </div>
		</div>
		<div class="col-sm-1 col-sm-offset-5">
			<a href="<%=path %>/social/statistical/exportCardMember">
			<shiro:hasPermission name="statistical_report:export">
			<button type="button" class="btn btn-primary">导出</button>
			</shiro:hasPermission>
			</a>
		</div>
	</div>
	
	<div class="row" style="margin-top: 20px;">
		<div class="col-sm-12">
			<table id="myTable" class="display">
				<thead>
					<tr>
						<th>姓名</th>
		                <th>电话</th>
		                <th>性别</th>
		                <th>邮箱</th>
		                <th>活动来源</th>
		                <th>状态</th>
		                <th>员工</th>
		                <th>操作</th>
					</tr>
				</thead>
			</table>
		</div>
	</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/artDialog/7.0.0/dialog-plus.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var myDataTable = null;
var memberDetailDialog = null;
$.fn.dataTable.ext.errMode = 'none';
$(function(){
	$("#contacted").change(function(){
		func_dataTableReload();
	});
	
	$("#search").click(function(){
		func_dataTableReload();
	});
	
	init();
});

function init(){
	myDataTable = dataTable();
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

function func_dataTableReload(resetPaging) {
	if(resetPaging != undefined){
	    myDataTable.ajax.reload(null,resetPaging);
	}else{
		myDataTable.ajax.reload();
	}
}


function func_AjaxUrl() {
    return path + "/social/statistical/getPageCardMember";
}

function func_columns() {
    var jsonArr = [
    	{"data": "name"},
        {"data": "phone"},
        {"data": "gender"},
        {"data": "email"},
        {"data": "activityName"},
        {"data": "contacted"},
        {"data": "username"},
        {"data": "memberId"}
    ];
    return jsonArr;
}

function func_ajaxData() {
    var jsonObject = new Object();
    jsonObject.contacted = $("#contacted").val();
    if($.trim($("#keyword").val()) != ""){
    	jsonObject.name = $.trim($("#keyword").val());
    }
    return jsonObject;
}

function dataTable() {
    return $('#myTable').DataTable({
        processing: true,
        ordering: false,
        searching: false,
        info: true,
        autoWidth: true,
        lengthChange: false,
        language: {
            emptyTable: '没有数据表',
            info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
            infoEmpty: '没有数据',
            lengthMenu: '每页显示 _MENU_ 条记录',
            loadingRecords: '正在加载数据....',
            processing: '正在处理数据....',
            zeroRecords: '没有找到匹配的记录',
            paginate: {
                first: '首页',
                previous: '前页',
                next: '后页',
                last: '尾页'
            }
        },
        order: [[1, 'desc']],
        pageLength: 10,
        pagingType: 'full_numbers',
        columnDefs: [{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	result = data;
                }
                return result;
            },
            targets: 0
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	result = data;
                }
                return result;
            },
            targets: 1
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	if(data == "m"){
                		result = "男";
                	}else if(data == "f"){
                		result = "女";
                	}else{
                		result = "未知";
                	}
                }
                return result;
            },
            targets: 2
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	result = data;
                }
                return result;
            },
            targets: 3
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	result = data;
                }
                return result;
            },
            targets: 4
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	if(data == 1){
                		result = "已联系";
                	}else if(data == 0){
                		result = "未联系";
                	}
                }
                return result;
            },
            targets: 5
		},{
            render: function (data, type, full) {
                var result = "";
                if(data != null){
                	result = data;
                }
                return result;
            },
            targets: 6
		},{
        	render: function (data, type, full) {
                var result = "";
//                 result += '<button onclick="func_showMemberDetailDialog(' + data + ')" class="btn btn-primary" type="button">编辑</button>&nbsp;';
                result += '<a onclick="func_showMemberDetailDialog(\'' + data + '\')" href="javascript:void(0)">编辑</a>&nbsp;';
                result += '<a onclick="func_markContacted(\'' + full.couponId + '\')" href="javascript:void(0)">标记联系</a>';
                return result;
            },
            targets: 7
        }],
        columns: func_columns(),
        serverSide: true,
        ajax: {
            contentType: 'application/json;charset=utf-8',
            type: 'POST',
            url: func_AjaxUrl(),
            data: function (d) {
                d.extra_search = func_ajaxData();
                return JSON.stringify(d);
            },dataSrc: function(d){
            	d.draw = d.data.draw;
                d.recordsTotal = d.data.recordsTotal;
                d.recordsFiltered = d.data.recordsFiltered;
                return d.data.data;
            }
        }
	});
}

//编辑会员
function func_showMemberDetailDialog(memberId) {
    memberDetailDialog = dialog({
        id: "memberDetailDialog",
        fixed: true,
        width: 900,
        height: 400,
        title: '会员详情',
        url: path + "/view/member/member/memberDetail?memberId=" + memberId,
        cancelValue: "关闭",
        cancel: function () {
			this.remove();
			func_dataTableReload(false);
		}
    });
    memberDetailDialog.showModal();
    $("iframe[name='memberDetailDialog']:visible").attr("scrolling", "auto").css("overflow-x", "hidden").css("overflow-y", "auto");
}

//标记联系
function func_markContacted(couponId){
	$.post(path+"/social/statistical/markContacted",{id:couponId},function(data){
		console.log(data);
		if(data.code == "200"){
			alert("标记成功");
			func_dataTableReload(false);
		}else{
			alert("操作失败");
		}
	},"json");
}
</script>
</html>